/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;
import java.util.stream.Stream;

/**
 * <p>Project: javaseapp - Stream1
 * <p>Powered by webrx On 2021-08-23 08:48:26
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Stream1 {
    public static void main(String[] args) {
        //Stream<Object>
        var sm1 = Stream.empty();
        //Stream<Integer> 流
        var sm2 = Stream.of(1, 2, 3);
        //Stream<Integer>
        var sm3 = Stream.iterate(1, a -> a + 2).limit(5); //1 3 5 7 9
        //sm3.forEach(System.out::println);
        //System.out.println(sm3.count());
        Random rand = new Random();
        String letter = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        var sm4 = Stream.generate(() -> {
            StringBuilder sbu = new StringBuilder();
            for (int i = 0; i < 8; i++) {
                sbu.append(letter.charAt(rand.nextInt(letter.length())));
            }
            return sbu.toString();
        }).limit(5);
        //System.out.println(sm4.count());
        //sm4.forEach(System.out::println);

        int[] num = new int[]{1, 2, 3};
        var sm5 = Arrays.stream(num);

        List<String> list = new ArrayList<>();
        list.add("java");
        list.add("javascript");
        var sm6 = list.stream();
        var sm7 = list.parallelStream();
        try {
            var br = new BufferedReader(new FileReader("D:\\ftp\\javase\\javaseapp\\10part\\src\\main\\java\\cn\\webrx\\Stream1.java"));
            var sm8 = br.lines();
            //System.out.println(sm8.count());
            AtomicInteger rows = new AtomicInteger();
            sm8.forEach(e -> {
                System.out.printf("%03d %s%n", rows.incrementAndGet(), e);
            });
        } catch (Exception e) {
            e.printStackTrace();
        }


        var s1 = "java,javascript,php,mysql,html,python";
        var p1 = Pattern.compile(",");
        var sm9 = p1.splitAsStream(s1);
        sm9.forEach(System.out::println);

    }
}
